<template>
  <div class="app-container">
    <el-card class="card-form">
      <div class="expert-title">专家库</div>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="专家姓名" prop="expertName">
          <el-input
            v-model="queryParams.expertName"
            placeholder="请输入"
            clearable
            style="width: 252px"
            maxlength="30"
          />
        </el-form-item>
        <el-form-item label="专业分类" prop="major">
          <el-select
            v-model="queryParams.major"
            placeholder="请选择"
            clearable
            style="width: 252px"
          >
            <el-option
              v-for="dict in majorOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="擅长领域" prop="areasOfExpertise">
          <el-select
            v-model="queryParams.areasOfExpertise"
            placeholder="请选择"
            clearable
            style="width: 252px"
          >
            <el-option
              v-for="dict in areasOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="handleQuery"
            >查询</el-button
          >
          <el-button size="small" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="card-table">
      <el-row :gutter="10" class="mb20 mt5">
        <!-- <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="small"
            @click="handleAdd"
            >添加专家</el-button
          >
        </el-col> -->
        <el-col :span="1.5">
          <el-button
            size="small"
            type="primary"
            @click="handleAdd"
            icon="el-icon-plus"
            v-hasPermi="['expert:list:add']"
            >添加专家</el-button
          >
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="expertList" border>
        <el-table-column label="序号" align="center" type="index" width="65" />
        <el-table-column
          label="专家姓名"
          align="center"
          prop="expertName"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="专业" align="center" prop="major" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{
              scope.row.major == 1
                ? "计算机科学与技术"
                : scope.row.major == 2
                ? "通信技术"
                : scope.row.major == 3
                ? "AI人工智能"
                : scope.row.major
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="擅长领域" align="center" prop="areasOfExpertise">
          <template slot-scope="scope">
            <span>{{
              scope.row.areasOfExpertise === '0'
                ? "土木工程"
                : scope.row.areasOfExpertise === '1'
                ? "财政"
                : scope.row.areasOfExpertise === '2'
                ? "环境保护"
                : scope.row.areasOfExpertise === '3'
                ? "计算机技术"
                : scope.row.areasOfExpertise === '4'
                ? "机械工程"
                : ''
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="工作单位" align="center" prop="workUnit" :show-overflow-tooltip="true"/>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="200px"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleView(scope.row)"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleDataScope(scope.row)"
              v-hasPermi="['expert:list:edit']"
              >编辑</el-button
            >
            <el-button size="mini" type="text" @click="handleDelete(scope.row)"
            v-hasPermi="['expert:list:del']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-show="total > 0"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="queryParams.pageSize"
        :current-page="queryParams.pageNum"
        :page-sizes="[10, 20, 30, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import {
  listExpert,
  getExpert,
  delExpert,
  addExpert,
  updateExpert,
} from "@/api/tripartite/expert";
export default {
  name: "Expert",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 专家表格数据
      expertList: [
        {
          roleId: "01",
          roleName: "胡涛华",
          roleKey: "计算机",
          roleSort: "计算机",
          roleSort: "重庆市渝北",
        },
      ],
      // 总条数
      total: 1,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        expertName: undefined,
        areasOfExpertise: undefined,
        major: undefined,
      },
      // 专家分类数据字典查询
      majorOptions: [],
      // 擅长领域数据字典查询
      areasOptions: [
        { dictValue: "0", dictLabel: "土木工程" },
        { dictValue: "1", dictLabel: "财务" },
        { dictValue: "2", dictLabel: "环境保护" },
        { dictValue: "3", dictLabel: "计算机技术" },
        { dictValue: "4", dictLabel: "机械工程" },
      ],
    };
  },
  // noReloaded: function () {
  //   if (location.href.indexOf("#reloaded") == -1) {
  //     location.href = location.href + "#reloaded";
  //     window.location.reload();
  //   }
  // },
  activated (){
    this.getList();
  },
  created() {
    // this.queryParams.pageNum = this.$route.query.pageNum;
    // this.queryParams.pageSize = this.$route.query.pageSize;
    this.getList();
    this.getDicts("areas_of_expertise").then((response) => {
      this.areasOptions = response.data;
    });
    this.getDicts("major").then((response) => {
      console.log('获取专业',response);
      this.majorOptions = response.data;
    });
  },
  methods: {
    /** 查询专家列表 */
    getList() {
      this.loading = true;
      listExpert(this.queryParams).then((response) => {
        this.expertList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/tripartite/expert/expertadd",
      });
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.$router.push({
        path: "/tripartite/expert/expertview",
        query: { expertId: row.expertId },
      });
    },
    /** 编辑按钮操作 */
    handleDataScope(row) {
      this.$router.push({
        path: "/tripartite/expert/expertadd",
        query: { expertId: row.expertId },
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const expertId = row.expertId;
      this.$confirm("是否确认删除 ？", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "del_box",
      })
        .then(function () {
          return delExpert(expertId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 分页 */
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
  },
};
</script>
<style scoped lang="scss">
.expert-title {
  font-size: 18px;
  font-family: PingFang SC, PingFang SC-Medium;
  font-weight: 500;
  margin-bottom: 24px;
  color: #000000;
}
.card-table {
  margin-top: 10px;
  .el-pagination {
    text-align: center;
    margin-top: 40px;
  }
}
</style>
<style lang="scss">
/**表单label取消加粗 */
.card-form {
  .el-card__body {
    padding-bottom: 0;
  }
  label {
    font-weight: normal !important;
  }
  .el-form--inline .el-form-item {
    margin-right: 60px;
  }
}
/* 删除弹出框样式 */
.del_box {
  width: 20%;
  .el-message-box__headerbtn {
    background: url("../../../assets/images/icon_dialog_close.png");
    background-size: 100%;
    width: 16px;
    height: 16px;
    .el-message-box__close {
      visibility: hidden;
    }
  }
  .el-message-box__content {
    border-top: 1px solid #ebecef;
    padding: 26px 95px;
    font-size: 16px;
    .el-message-box__status.el-icon-warning {
      color: #ea4747;
    }
    .el-message-box__status + .el-message-box__message {
      padding-right: 0;
    }
  }
}
</style>
